Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
merge-options-es5
Advanced tools
Merge Option Objects
merge-options
considers plain objects as Option Objects, everything else as Option Values.
$ npm install --save merge-options
const mergeOptions = require('merge-options');
mergeOptions({foo: 0}, {bar: 1}, {baz: 2}, {bar: 3})
//=> {foo: 0, bar: 3, baz: 2}
mergeOptions({nested: {unicorns: 'none'}}, {nested: {unicorns: 'many'}})
//=> {nested: {unicorns: 'many'}}
mergeOptions({[Symbol.for('key')]: 0}, {[Symbol.for('key')]: 42})
//=> {Symbol(key): 42}
mergeOptions
recursively merges one or more Option Objects into a new one and returns that. The options
are merged in order, thus Option Values of additional options
take precedence over previous ones.
The merging does not alter the passed option
arguments, taking roughly the following steps:
const defaultOpts = {
fn: () => false, // functions are Option Values
promise: Promise.reject(new Error()), // all non-plain objects are Option Values
array: ['foo'], // arrays are Option Values
nested: {unicorns: 'none'} // {…} is plain, therefore an Option Object
};
const opts = {
fn: () => true, // [1]
promise: Promise.resolve('bar'), // [2]
array: ['baz'], // [3]
nested: {unicorns: 'many'} // [4]
};
mergeOptions(defaultOpts, opts)
//=>
{
fn: [Function], // === [1]
promise: Promise { 'bar' }, // === [2]
array: ['baz'], // !== [3] (arrays are cloned)
nested: {unicorns: 'many'} // !== [4] (Option Objects are cloned)
}
Type: object
Type: boolean
Default: false
Concatenate arrays:
mergeOptions({src: ['src/**']}, {src: ['test/**']})
//=> {src: ['test/**']}
// Via call
mergeOptions.call({concatArrays: true}, {src: ['src/**']}, {src: ['test/**']})
//=> {src: ['src/**', 'test/**']}
// Via apply
mergeOptions.apply({concatArrays: true}, [{src: ['src/**']}, {src: ['test/**']}])
//=> {src: ['src/**', 'test/**']}
MIT © Michael Mayer
FAQs
ES5-Compatible Merge Option Objects
The npm package merge-options-es5 receives a total of 46 weekly downloads. As such, merge-options-es5 popularity was classified as not popular.
We found that merge-options-es5 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.